package com.abu.notice.config.pool;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Component
public class NoticeThreadPoolExecutor {


    @Bean
    public ThreadPoolExecutor threadPoolExecutor() {

        int processorsCount = Runtime.getRuntime().availableProcessors();
        return new ThreadPoolExecutor(
                processorsCount * 2,
                50,
                5, TimeUnit.MINUTES,
                new LinkedBlockingQueue<>(500),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.DiscardPolicy()
        );
    }
}
